<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="<c:url value="/js/jquery.js"/>"></script>
    <script type="text/javascript">
        $(document).ready(function(){
           //当前选中的下拉框
	     var currentSelect;
	     //当前父类别选项的值
         var currentValue="";
	  
        //住下拉框发生改变时，做出响应
         $("select").change(function(){
         
          currentSelect=$(this);
          currentValue=currentSelect.val();
          
          if(currentValue==0){
        	  alert("aaa");
        	//  document.all['oopp'].length=0;
        	  var d=document.getElementById("oopp");
              d.style.display='none';
              return "";
          }
          
          $.post("<c:url value="/category"/>",{"act":"getChildCategory","parentNo":currentValue,"seed":Math.random()},
            function(data){
              
                if(data.length!=0){
                    var ss=$("<div id='ddd'></div>");
                    var ch=$("<select name='ctg_no' id='oopp'></select>").appendTo(ss);
           //        var childSelect=$("<select id='oopp'></select>");
                    $("<option>=请选择=</option>").appendTo(ch);
                   
					
                 //   var str="<option id='oopp'>=请选择=</option>";
                  //  alert("");
                 //   $("<select></select>").html(str);
                     var obj=eval("("+data+")");
                    for(i=0;i<obj.employee.length;i++){
                      $("<option value='"+obj.employee[i].categoryNo+"'>"+obj.employee[i].categoryNo+obj.employee[i].categoryName+"</option>").appendTo(ch);
                    }
                 
                    ch.insertAfter(currentSelect);
                    
                }
                else{
                    alert("无下级层次");
                    var d=document.getElementById("oopp");
            	    d.style.display='none';
                } 
          
          });//end post()
          
        });//end change
        
        });//end ready
          onsubmit=function(){
      //      alert("aaa");
            //判断空
             with(document.forms[0]){
	            
	            //检测是否有未填写的信息
	          if(ctg_no.value==""){
	            alert("请填写类别编号！");
                return false;
	          }
	          if(goods_no.value==""){
                alert("请填写商品编号！");
                return false;
              }
              if(isNaN(goods_no.value)){
                 alert("商品编号只能为数字！");
                 return false;
              }
               if(goods_name.value==""){
                alert("请填写商品名称！");
                return false;
              }
	          if(goods_price.value==""){
	                alert("商品单格不能为空,请检查!");
	                return false;
	          }
	          if(isNaN(goods_price.value)){
                 alert("商品单格只能为数字！");
                 return false;
              }
	          if(goods_num.value==""){
	                alert("商品数量不能为空,请检查!");
	                return false;
	          }
	          if(goods_price(goods_num.value)){
                 alert("商品数量只能为数字！");
                 return false;
              }
	        }
	         
              var price;
              price=parseInt(goods_price.value);
     	          
             if(price<0){
                alert("商品价格不能为负数！");
                return false;
             }
             var num;
              num=parseInt(goods_num.value);
             if(num<-0){
                alert("请填写商品数量！");
                return false;
             }
           return true;
      }
     
</script>
  </head>
  <body>
      <div class="title">
          <h3>添加商品</h3>
      </div>
      <hr/>
      <div class="wrapper">
      <form class="content_form" action="<c:url value="/goods"/>" method="post" enctype="multipart/form-data">
              <input type="hidden" name="act" value="add"/>
         <!--   <form class="content_form" action="<c:url value="/goods"/>" method="post" enctype="multipart/form-data">
              <input type="hidden" name="act" value="add"/>
              -->
              <!--  <div class="wrapper_div">
                  <span>请选择类别:</span>
                  <select class="main_select" name="ctg_no">
                      <option value="0">=请选择=</option>
                      <c:forEach items="${categoryList}" var="category">
                        <option value="${category.categoryNo}">${category.categoryName}</option>
                      </c:forEach>
                  </select>
              </div>
              -->
              <div class="wrapper_div">
                  <span>商品所属类别:</span>
                  <select class="main_select" name="ctg_no">
                      <option value="">无</option>
                      <c:forEach items="${categoryList}" var="category">
                        <option value="${category.categoryNo}">${category.categoryNo} ${category.categoryName}</option>
                      </c:forEach>
                  </select>
              </div>
              <div class="wrapper_div">
                  <span>输入商品编号:</span>
                  <input type="text" name="goods_no"/>
              </div>
              <div class="wrapper_div">
                  <span>输入商品名称:</span>
                  <input type="text" name="goods_name"/>
              </div>
              <div class="wrapper_div">
                  <span>输入商品单价:</span>
                  <input type="text" name="goods_price"/>
              </div>
              <div class="wrapper_div">
                  <span>输入商品数量:</span>
                  <input type="text" name="goods_num"/>
              </div>
              <div class="wrapper_div">
                  <span>输入商品图片:</span>
                  <input type="file" name="goods_pic"/>
              </div>
              <div class="wrapper_div">
                  <span>输入商品描述:</span>
                  <textarea rows="8" cols="60" name="goods_memo" >请填写该商品的详细信息，以便对产品更加了解！</textarea>
              </div>
              <div class="wrapper_div">
                  <input type="submit" value="提交"/> 
                  <input type="reset" value="重置"/>
              </div>
          </form>
      </div>
  </body>
</html>
